#!/usr/bin/env python

import sqlite3
import cgi
import json

conn = sqlite3.connect('/db/metanode.db')
cur = conn.cursor()
#cur.execute("DROP TABLE idare_jobs;")
#cur.execute("CREATE TABLE idare_jobs(name text, email text, org text, project text, imgformat text, handshake text, status text default 'new', jobid INTEGER PRIMARY KEY AUTOINCREMENT);")

qform = cgi.FieldStorage()
#jobid = "13"#
jobid = qform.getvalue('jobID')
#handshake = "GCUVKZ"#
handshake = qform.getvalue('handshake')

cur.execute("select count(*) from idare_jobs where jobid = " + jobid + " and handshake ='" + handshake + "'")
res = cur.fetchone()
#print (res[0])
conn.close()
pa = {}
pa['_jobcount'] = res[0]
print "Content-type: text/html;charset=utf-8\r\n"
print json.dumps(pa)
#check that jobid and handshake are valid, else return -1
